package drename;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;

import jmetal.util.MathUtil;

public class ComputeMeanIGD {
	public static void main(String[] args) throws IOException {
		String algorithm = "NSGAIII";
		String problems = "DTLZ";
		Integer[] dimensions = {5};
		for(int i = 0;i<4;i++){
			String problem = problems+(i+1);
			String direct = "output_data/"+algorithm+"/"+problem+"/";
			FileOutputStream output = new FileOutputStream(new File(direct+"mean_IGD.dat"));
			for(int j = 0;j<dimensions.length;j++)
			{
				String path = direct+"/"+dimensions[j]+"D_IGD.dat";
				FileReader reader = new FileReader(new File(path));
				BufferedReader buffer = new BufferedReader(reader);
				int number = 0;
				String str = null;
				double[] igds = new double[30];
				while((str=buffer.readLine())!=null){
					String[] splitStr = str.split(" ");
					igds[number] = Double.parseDouble(splitStr[1]);
					number++;
				}
				buffer.close();
				
				Double mean = MathUtil.getAvarage(igds);
				double std = MathUtil.getStd(igds);
				DecimalFormat dfAve = new DecimalFormat("0.0000E00");
				DecimalFormat dfStd = new DecimalFormat("0.00E00");
				String out = dfAve.format(mean)+" "+dfStd.format(std)+"\n";
				output.write(out.getBytes());
			}
			output.close();
			
		}
		System.out.println("end");
	}
}
